import axios from 'axios'
import { Message } from 'element-ui';

// let baseUrl = 'https://www.jiajingtuzhuang.xyz'
let baseUrl='/'
// let baseUrl = ''
/* axios实例 */
const instance = axios.create({
  baseURL:baseUrl,
  timeout: 60000,
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json'
  }
})
/* 请求拦截器 */
instance.interceptors.request.use(
  config => {
    if (localStorage.getItem("token")) {
      config.headers.token = localStorage.getItem("token")
    }
    return config
  },
  err => {
    return Promise.reject(err)
  }
)
/* 响应拦截器 */
instance.interceptors.response.use(
  response => {
    if (response.data.status == 500) {
      this.$message({
        type: "error",
        message: response.data.message
      })
    }
    return response
  },
  err => {
    Message({
      type: "error",
      message: err.response.data.message


    })
    return Promise.reject(err)
  }
)

export {instance}
